package com.lgq.cfw.service.impl;

import com.lgq.cfw.bean.TableAccountTypeCert;
import com.lgq.cfw.bean.TableCert;
import com.lgq.cfw.bean.example.TableAccountTypeCertExample;
import com.lgq.cfw.bean.example.TableAccountTypeCertExample.Criteria;
import com.lgq.cfw.dao.TableAccountTypeCertMapper;
import com.lgq.cfw.dao.TableCertMapper;
import com.lgq.cfw.service.AccountTypeAndCertService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Lin
 * @date 2019-02-12 15:57
 **/
@Service
public class AccountTypeAndCertServiceImpl implements AccountTypeAndCertService {

  @Autowired
  TableAccountTypeCertMapper tableAccountTypeCertMapper;

  /**
   * 获取用户类型和资质要求的信息
   * @return list
   */
  @Override
  public  List<TableAccountTypeCert> getAccountTypeAndCert() {
    return tableAccountTypeCertMapper.selectByExample(null);
  }

  /**
   * 删除所有
   * @return 布尔
   */
  @Override
  public boolean deleteAll() {
    try {
      tableAccountTypeCertMapper.deleteByExample(null);
    }catch (Exception e){
      e.printStackTrace();
      return false;
    }
    return true;
  }

  /**
   * 更新资质和类型关系
   * @param updateString 更新的字符串
   */
  @Override
  public void updateAccountTypeAndCert(String updateString) {
    TableAccountTypeCert tableAccountTypeCert=new TableAccountTypeCert();
    String[] group = updateString.split("-");
    for (String string1:group) {
      String[] single = string1.split(",");
      Integer type=Integer.parseInt(single[0]);
      if (type.equals(1)){
        tableAccountTypeCert.setAccttype("商业公司");
      }else if (type.equals(2)){
        tableAccountTypeCert.setAccttype("个体工商户");
      }else if (type.equals(3)){
        tableAccountTypeCert.setAccttype("个人经营");
      }else if (type.equals(4)){
        tableAccountTypeCert.setAccttype("政府及非营利组织");
      }
      Integer cert=Integer.parseInt(single[1]);
      tableAccountTypeCert.setCertid(cert);
      tableAccountTypeCertMapper.insertSelective(tableAccountTypeCert);
    }
  }
}
